<?php
include_once ROOT_DIR."/bc/block.user.php";
function bend_user(&$retparams){
	global $_db;
	
	if("addview"==$_POST['op']){
		echo rendertpl("applet/useraddmod.applet", array("title"=>"添加案例"));
		return BEND_RENDERED;
	}
	elseif("add"==$_POST['op']){
		$id = $_db->insert("user", array("login"=>@$_POST['login'],"passwd"=>md5(@$_POST['passwd']),"name"=>@$_POST['name'],"gender"=>@$_POST['gender'],"mobile"=>@$_POST['mobile'],"othercontact"=>@$_POST['othercontact'],"city"=>@$_POST['city'],"address"=>@$_POST['address'],"age"=>@$_POST['age'],"phone"=>@$_POST['phone'],"qq"=>@$_POST['qq'],"msn"=>@$_POST['msn'],"email"=>@$_POST['email'],"orgid"=>@$_POST['orgid'],"topayratio"=>@$_POST['topayratio'],"paysrcratio"=>@$_POST['paysrcratio'],"payrecratio"=>@$_POST['payrecratio'],"bankcard"=>@$_POST['bankcard'],"bank"=>@$_POST['bank'],"bankcity"=>@$_POST['bankcity'],"recid"=>@$_POST['recid'],"remark"=>@$_POST['remark'],"lastlogin"=>@$_POST['lastlogin'],"deleted"=>@$_POST['deleted']));
		if($id>0){
			$retparams['errorcode'] = 0;
		}
		else{
			$retparams['errorcode'] = -1;
		}
		return BEND_ECHORET;
	}
	elseif("del"==$_POST['op']){
		$count = $_db->delete("user", "id=$_POST[id]");
	}
	elseif("modview"==$_POST['op']){
		echo rendertpl("applet/useraddmod.applet", array("title"=>"修改案例"));
		return BEND_RENDERED;
	}
	elseif("mod"==$_POST['op']){
		$count = $_db->update("user", array("login"=>@$_POST['login'],"passwd"=>@$_POST['passwd'],"name"=>@$_POST['name'],"gender"=>@$_POST['gender'],"mobile"=>@$_POST['mobile'],"othercontact"=>@$_POST['othercontact'],"city"=>@$_POST['city'],"address"=>@$_POST['address'],"age"=>@$_POST['age'],"phone"=>@$_POST['phone'],"qq"=>@$_POST['qq'],"msn"=>@$_POST['msn'],"email"=>@$_POST['email'],"orgid"=>@$_POST['orgid'],"topayratio"=>@$_POST['topayratio'],"paysrcratio"=>@$_POST['paysrcratio'],"payrecratio"=>@$_POST['payrecratio'],"bankcard"=>@$_POST['bankcard'],"bank"=>@$_POST['bank'],"bankcity"=>@$_POST['bankcity'],"recid"=>@$_POST['recid'],"remark"=>@$_POST['remark'],"lastlogin"=>@$_POST['lastlogin'],"deleted"=>@$_POST['deleted']),"id=$_POST[id]");
		if($count>0){
			$retparams['errorcode'] = 0;
		}
		else{
			$retparams['errorcode'] = -1;
		}
		return BEND_ECHORET;
	}
	elseif("search"==$_POST['op']){
		return BEND_HOMEPAGE;
	}
	elseif("ajaxsearchinadd"==$_POST['op']){
		$params = $_POST;
		$users = getuser($params);
		echo json_encode($users);
		//error_log("hre:".json_encode($users));
		return BEND_RENDERED;
	}
	return BEND_REDIRECT;
}
?>